// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/

import UIKit

public struct MenuElement: Equatable, Sendable {
    public let title: String
    let description: String?
    let iconName: String
    let iconImage: UIImage?
    let needsReAuth: Bool?
    let isEnabled: Bool
    let isActive: Bool
    let a11yLabel: String?
    let a11yHint: String?
    let a11yId: String
    let isOptional: Bool
    let infoTitle: String?
    public let action: (@MainActor @Sendable () -> Void)?

    // We need this init as by default the init generated by the compiler
    // for the struct will be internal and can not be used outside of MenuKit
    public init(
        title: String,
        description: String? = nil,
        iconName: String,
        iconImage: UIImage? = nil,
        needsReAuth: Bool? = nil,
        isEnabled: Bool,
        isActive: Bool,
        a11yLabel: String?,
        a11yHint: String?,
        a11yId: String,
        isOptional: Bool = false,
        infoTitle: String? = nil,
        action: (@MainActor @Sendable () -> Void)?
    ) {
        self.title = title
        self.description = description
        self.iconName = iconName
        self.iconImage = iconImage
        self.needsReAuth = needsReAuth
        self.isEnabled = isEnabled
        self.isActive = isActive
        self.a11yLabel = a11yLabel
        self.a11yHint = a11yHint
        self.a11yId = a11yId
        self.action = action
        self.isOptional = isOptional
        self.infoTitle = infoTitle
    }

    public static func == (lhs: MenuElement, rhs: MenuElement) -> Bool {
        return lhs.title == rhs.title &&
        lhs.description == rhs.description &&
        lhs.iconName == rhs.iconName &&
        lhs.iconImage ==  rhs.iconImage &&
        lhs.needsReAuth == rhs.needsReAuth &&
        lhs.isEnabled == rhs.isEnabled &&
        lhs.isActive == rhs.isActive &&
        lhs.a11yLabel == rhs.a11yLabel &&
        lhs.a11yHint == rhs.a11yHint &&
        lhs.a11yId == rhs.a11yId &&
        lhs.isOptional == rhs.isOptional &&
        lhs.infoTitle == rhs.infoTitle
    }
}
